const state = {
  // cardConfig: null // 卡余额限制的配置
  rechargeLimit: null, // 提示充值的余额限制
  qrcodeBalanceLimit: null, // 展示二维码的余额限制
  lowBalanceDesc: null, // 低余额的说明页地址
  qrcodePosBillLimit: null // 失败行程次数限制
}

const getters = {
  // cardConfig: state => state.cardConfig
  rechargeLimit: state => state.rechargeLimit,
  qrcodeBalanceLimit: state => state.qrcodeBalanceLimit,
  lowBalanceDesc: state => state.lowBalanceDesc,
  qrcodePosBillLimit: state => state.qrcodePosBillLimit
}

const actions = {
  fetchCardConfig: ({ commit, state }, text) => {
    commit('updateCardConfig', text)
  }
}

const mutations = {
  updateCardConfig: (state, payload) => {
    // state.CardConfig = payload
    state.rechargeLimit = formatLimitMoney(payload.RECHARGE_LIMIT || 0)
    state.qrcodeBalanceLimit = formatLimitMoney(
      payload.QRCODE_BALANCE_LIMIT || 0
    )
    state.lowBalanceDesc = payload.LOW_BALANCE_DESC
    state.qrcodePosBillLimit = payload.QRCODR_POSBILL_LIMIT || 0
  }
}

// 将价格从分转为元
const formatLimitMoney = function(money) {
  return money / 100
}

export default {
  state,
  getters,
  actions,
  mutations
}
